package com.blackitheima.test3;

import java.util.*;
import java.util.stream.Stream;

public class MyStream1 {
    public static void main(String[] args) {
        //单列集合Stream流
        ArrayList<String> list=new ArrayList<>(
                List.of("张三丰","张无忌","张量","六小龄童"));
        list.stream().filter(s->s.startsWith("张"))
                .limit(2).forEach(s-> System.out.println(s));
        System.out.println("===================");
        //双列集合Stream流
        TreeMap<String,Integer> map=new TreeMap<>(
                Map.of("张三三",23,"李四",22,"雪域",24));
        map.keySet().stream().filter(s->s.length()==2).forEach(s-> System.out.println(s));
        System.out.println("-------------------------");
        map.entrySet().stream().filter(s->s.getKey().startsWith("雪"))
                .forEach(s-> System.out.println(s));
        System.out.println("====================");

        //数组stream流
        int[]arr={1,2,3,4,5};
        Arrays.stream(arr).filter(s->s>3).forEach(s-> System.out.println(s));
        System.out.println("======================");
        //数据类型相同
        Stream.of("abr","abc","dere","aer").filter(s->s.length()==3).limit(2)
                .forEach(s-> System.out.println(s));

    }
}
